<template>
  <Layout type="Declaration">
    <div v-if="columns.length>0" class="Declaration" :class="isFull ? 'full' : ''">
      <div class="Declaration-head">
        <div class="title" @click="handleType">
          {{ filterChooseText(chooseText)
          }}<span class="font_family icon-gengduo"></span>
        </div>
        <div class="opera">
          <span
            class="font_family icon-shaixuan"
            @click="showMenu = !showMenu"
          ></span>
          <!-- <span class="font_family icon-fangda"></span> -->
          <!-- <span class="font_family icon-suoxiao" style="display: none"></span> -->
        </div>
      </div>
      <!-- :immediate-check="false" -->
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
      >
        <declarationTable
          v-if="menuType == 1"
          :config="tableConfig1"
          :data="dataList"
        />
        <declarationTable
          v-else-if="menuType == 2"
          :config="tableConfig2"
          :data="dataList"
        />
        <declarationTable
          v-else-if="menuType == 3"
          :config="tableConfig3"
          :data="dataList"
        />
        <declarationTable
          v-else-if="menuType == 4"
          :config="tableConfig4"
          :data="dataList"
        />
        <declarationTable
          v-else-if="menuType == 5"
          :config="tableConfig5"
          :data="dataList"
        />
        <declarationTable
          v-else-if="menuType == 6"
          :config="tableConfig6"
          :data="dataList"
        />
        <declarationTable
          v-else-if="menuType == 7"
          :config="tableConfig7"
          :data="dataList"
        />
        <declarationTable
          v-else-if="menuType == 8"
          :config="tableConfig8"
          :data="dataList"
        />
        <declarationTable
          v-else-if="menuType == 9"
          :config="tableConfig9"
          :data="dataList"
        />
        <declarationTable
          v-else-if="menuType == 10"
          :config="tableConfig10"
          :data="dataList"
        />
      </van-list>
      <!-- <div v-if="showLoading && !finished" class="loading">
        <van-loading size="16px">加载中...</van-loading>
      </div> -->
      <!-- declaration-menu -->
      <declarationMenu
        v-show="showMenu"
        :menuType="menuType"
        @getFrom="setForm"
      />
      <!-- 筛选 -->
      <van-popup position="bottom" v-model="showPop">
        <van-picker
          show-toolbar
          :columns="columns"
          @confirm="onConfirm"
          @cancel="showPop = false"
        />
      </van-popup>
    </div>
    <no-data  v-if="isNoData" :noDataText="noDataText"></no-data>
    <quit></quit>
  </Layout>
</template>
<script>
import Layout from "@/layout";
import declarationMenu from "@/components/declaration-menu";
import declarationTable from "@/components/declaration-table";
import { getTableInfo, getTableOptions } from "@/api/declaration";
import Quit from "@/components/quit";
import {
  createForm1,
  createForm2,
  createForm8,
  createForm9,
  createForm10,
} from "@/utils/declaration-data";
import NoData from '../components/noData.vue';

export default {
  name: "Declaration",
  components: {
    Layout,
    declarationMenu,
    declarationTable,
    Quit,
    NoData,
  },
  data() {
    return {
      menuType:0,
      query: {
        page: 1,
      },
      form: createForm1(),
      isFull: false,
      showPop: false,
      chooseText: "",
      columns: [],
      columnsId: [],
      showMenu: false,
      dataList: [],
      tableConfig1: [
        { label: "序号", type: "index", width: "60" },
        { label: "服务单ID", prop: "req_id", width: "150" },
        { label: "服务单名称", prop: "req_name", width: "150" },
        { label: "需求一级分类", prop: "typeone", width: "200" },
        { label: "需求二级分类", prop: "typetwo", width: "200" },
        { label: "提交至IT工作台时间", prop: "applytime", width: "250" },
        { label: "当前阶段", prop: "current_node", width: "180" },
        { label: "板块名称", prop: "plate_name", width: "180" },
        { label: "涉及系统", prop: "invovle_sys", width: "180" },
        { label: "系统负责人", prop: "sys_mgr", width: "180" },
        { label: "所在团队", prop: "teamname", width: "180" },
        { label: "服务单截止时间", prop: "finishtime", width: "250" },
        { label: "剩余时间", prop: "lefttime", width: "180" },
        { label: "需求实施完成时间", prop: "req_finish_time", width: "250" },
      ],
      tableConfig2: [
        { label: "序号", type: "index", width: "60" },
        { label: "需求编号", prop: "requirement_number", width: "150" },
        { label: "服务单名称", prop: "server_name", width: "150" },
        { label: "阶段", prop: "oa_node", width: "200" },
        { label: "提交至IT工作台时间", prop: "submit_time", width: "200" },
        { label: "当前阶段", prop: "current_node", width: "180" },
        { label: "当前办理人", prop: "current_person", width: "180" },
        { label: "起草时间", prop: "start_time", width: "180" },
        { label: "总公司对口部门", prop: "head_department", width: "180" },
        { label: "申请部门", prop: "apply_department", width: "180" },
        { label: "项目负责人", prop: "project_head_user", width: "250" },
        { label: "硬件金额（万元）", prop: "hardware_money", width: "250" },
        { label: "系统编号", prop: "system_number", width: "180" },
        { label: "系统名称", prop: "system_name", width: "250" },
        { label: "系统负责人", prop: "system_head_user", width: "250" },
        { label: "所属团队", prop: "team", width: "250" },
        { label: "实施内容", prop: "implementation_content", width: "250" },
        { label: "资源类型", prop: "resource_type", width: "250" },
        { label: "合作商", prop: "partner", width: "250" },
        { label: "单价（万元）", prop: "price", width: "250" },
        { label: "预计人月", prop: "workflow", width: "250" },
        { label: "预计IT投入（万元）", prop: "it_money", width: "250" },
        { label: "项目编号", prop: "project_number", width: "250" },
        { label: "实施周期", prop: "implementation_cycle", width: "250" },
        {
          label: "预计提交用户验收时间",
          prop: "plan_check_Time",
          width: "250",
        },
        {
          label: "需求分析预计提交用户验收",
          prop: "requirement_analysis_time",
          width: "250",
        },
      ],
      tableConfig3: [
        { label: "序号", type: "index", width: "60" },
        { label: "服务单id", prop: "req_id", width: "150" },
        { label: "服务单名称", prop: "req_name", width: "150" },
        { label: "需求一级分类", prop: "typeone", width: "200" },
        { label: "需求二级分类", prop: "typetwo", width: "200" },
        { label: "当前阶段", prop: "current_node", width: "180" },
        { label: "提交至IT工作台时间", prop: "starttime", width: "180" },
        { label: "当前办理人所在处室", prop: "unitname", width: "180" },
        { label: "当前办理人", prop: "curuser", width: "180" },
        { label: "总公司对口部门", prop: "headdept", width: "180" },
        { label: "当前节点流入时间", prop: "current_node_time", width: "180" },
        { label: "起草时间", prop: "applyTime", width: "180" },
        { label: "已阅时间", prop: "FirstReadTime", width: "180" },
        { label: "提数时间", prop: "get_data_time", width: "180" },
        
        { label: "起草至今时效", prop: "overdue_days", width: "180" },
        {
          label: "起草至今标准时效",
          prop: "max_start_standard_time",
          width: "180",
        },
        {
          label: "起草至今时效状态",
          prop: "start_start_time_status",
          width: "180",
        },
        { label: "已阅时效", prop: "read_overdue_days", width: "180" },
        {
          label: "已阅标准时效",
          prop: "max_read_standard_time",
          width: "180",
        },
        { label: "已阅失效状态", prop: "start_read_time_status", width: "180" },
      ],
      tableConfig4: [
        { label: "序号", type: "index", width: "60" },
        { label: "服务单id", prop: "req_id", width: "150" },
        { label: "服务单名称", prop: "req_name", width: "150" },
        { label: "需求一级分类", prop: "typeone", width: "200" },
        { label: "需求二级分类", prop: "typetwo", width: "200" },
        { label: "当前阶段", prop: "current_node", width: "180" },
        { label: "提交至IT工作台时间", prop: "starttime", width: "180" },
        { label: "当前办理人所在处室", prop: "unitname", width: "180" },
        { label: "当前办理人", prop: "curuser", width: "180" },
        { label: "总公司对口部门", prop: "headdept", width: "180" },
        { label: "当前节点流入时间", prop: "current_node_time", width: "180" },
        { label: "起草时间", prop: "applyTime", width: "180" },
        { label: "已阅时间", prop: "FirstReadTime", width: "180" },
        { label: "提数时间", prop: "get_data_time", width: "180" },
        { label: "起草至今时效", prop: "overdue_days", width: "180" },
        {
          label: "起草至今标准时效",
          prop: "max_start_standard_time",
          width: "180",
        },
        {
          label: "起草至今时效状态",
          prop: "start_start_time_status",
          width: "180",
        },
        { label: "已阅时效", prop: "read_overdue_days", width: "180" },
        {
          label: "起草标准时效",
          prop: "max_read_standard_time",
          width: "180",
        },
        { label: "已阅失效状态", prop: "start_read_time_status", width: "180" },
      ],
      tableConfig5: [
        { label: "序号", type: "index", width: "60" },
        { label: "服务单id", prop: "req_id", width: "150" },
        { label: "服务单名称", prop: "req_name", width: "150" },
        { label: "需求一级分类", prop: "typeone", width: "200" },
        { label: "需求二级分类", prop: "typetwo", width: "200" },
        { label: "当前阶段", prop: "current_node", width: "180" },
        { label: "提交至IT工作台时间", prop: "starttime", width: "180" },
        { label: "当前办理人所在处室", prop: "unitname", width: "180" },
        { label: "当前办理人", prop: "curuser", width: "180" },
        { label: "总公司对口部门", prop: "headdept", width: "180" },
        { label: "当前节点流入时间", prop: "current_node_time", width: "180" },
        { label: "起草时间", prop: "applyTime", width: "180" },
        { label: "已阅时间", prop: "FirstReadTime", width: "180" },
        { label: "提数时间", prop: "get_data_time", width: "180" },
        { label: "起草至今时效", prop: "overdue_days", width: "180" },
        {
          label: "起草至今标准时效",
          prop: "max_start_standard_time",
          width: "180",
        },
        {
          label: "起草至今时效状态",
          prop: "start_start_time_status",
          width: "180",
        },
        { label: "已阅时效", prop: "read_overdue_days", width: "180" },
        {
          label: "已阅标准时效",
          prop: "max_read_standard_time",
          width: "180",
        },
        { label: "已阅失效状态", prop: "start_read_time_status", width: "180" },
      ],
      tableConfig6: [
        { label: "序号", type: "index", width: "60" },
        { label: "服务单id", prop: "req_id", width: "150" },
        { label: "服务单名称", prop: "req_name", width: "150" },
        { label: "需求一级分类", prop: "typeone", width: "200" },
        { label: "需求二级分类", prop: "typetwo", width: "200" },
        { label: "当前阶段", prop: "current_node", width: "180" },
        { label: "提交至IT工作台时间", prop: "starttime", width: "180" },
        { label: "当前办理人所在处室", prop: "unitname", width: "180" },
        { label: "当前办理人", prop: "curuser", width: "180" },
        { label: "总公司对口部门", prop: "headdept", width: "180" },
        { label: "当前节点流入时间", prop: "current_node_time", width: "180" },
        { label: "起草时间", prop: "applyTime", width: "180" },
        { label: "已阅时间", prop: "FirstReadTime", width: "180" },
        { label: "提数时间", prop: "get_data_time", width: "180" },
        { label: "起草至今时效", prop: "overdue_days", width: "180" },
        {
          label: "起草至今标准时效",
          prop: "max_start_standard_time",
          width: "180",
        },
        {
          label: "起草至今时效状态",
          prop: "start_start_time_status",
          width: "180",
        },
        { label: "已阅时效", prop: "read_overdue_days", width: "180" },
        {
          label: "已阅标准时效",
          prop: "max_read_standard_time",
          width: "180",
        },
        { label: "已阅失效状态", prop: "start_read_time_status", width: "180" },
      ],
      tableConfig7: [
        { label: "序号", type: "index", width: "60" },
        { label: "服务单id", prop: "req_id", width: "150" },
        { label: "服务单名称", prop: "req_name", width: "150" },
        { label: "需求一级分类", prop: "typeone", width: "200" },
        { label: "需求二级分类", prop: "typetwo", width: "200" },
        { label: "当前阶段", prop: "current_node", width: "180" },
        { label: "提交至IT工作台时间", prop: "starttime", width: "180" },
        { label: "当前办理人所在处室", prop: "unitname", width: "180" },
        { label: "当前办理人", prop: "curuser", width: "180" },
        { label: "总公司对口部门", prop: "headdept", width: "180" },
        { label: "当前节点流入时间", prop: "current_node_time", width: "180" },
        { label: "起草时间", prop: "applyTime", width: "180" },
        { label: "已阅时间", prop: "FirstReadTime", width: "180" },
        { label: "提数时间", prop: "get_data_time", width: "180" },
        { label: "起草至今时效", prop: "overdue_days", width: "180" },
        {
          label: "起草至今标准时效",
          prop: "max_start_standard_time",
          width: "180",
        },
        {
          label: "起草至今时效状态",
          prop: "start_start_time_status",
          width: "180",
        },
        { label: "已阅时效", prop: "read_overdue_days", width: "180" },
        {
          label: "已阅标准时效",
          prop: "max_read_standard_time",
          width: "180",
        },
        { label: "已阅失效状态", prop: "start_read_time_status", width: "180" },
      ],
      tableConfig8: [
        { label: "序号", type: "index", width: "60" },
        { label: "服务单id", prop: "req_id", width: "150" },
        { label: "服务单名称", prop: "req_name", width: "150" },
        { label: "业务部门", prop: "headDept", width: "150" },
        { label: "需求二级分类", prop: "typetwo", width: "200" },
        { label: "当前阶段", prop: "current_node", width: "180" },
        { label: "处理人所属团队", prop: "teamname", width: "180" },
        { label: "系统开发负责人", prop: "current_person", width: "180" },
        { label: "当前节点流入时间", prop: "current_node_time", width: "180" },
        { label: "预计提交验收时间", prop: "plan_check_Time", width: "250" },
      ],
      tableConfig9: [
        { label: "序号", type: "index", width: "60" },
        { label: "员工姓名", prop: "name", width: "150" },
        { label: "所在处室", prop: "dept", width: "150" },
        { label: "公司职务", prop: "postname", width: "200" },
        { label: "项目名", prop: "projectname", width: "200" },
        { label: "项目结束时间", prop: "project_end_date", width: "180" },
        { label: "项目角色", prop: "project_role", width: "180" },
        { label: "工作内容", prop: "work_content", width: "180" },
        { label: "起始参与时间", prop: "start_date", width: "180" },
        { label: "结束参与时间", prop: "end_date", width: "180" },
        { label: "本项目工作日合计（天/人）", prop: "total_day", width: "150" },
        { label: "一月标准工作日", prop: "total_day1", width: "150" },
        { label: "二月标准工作日", prop: "total_day2", width: "150" },
        { label: "三月标准工作日", prop: "total_day3", width: "150" },
        { label: "四月标准工作日", prop: "total_day4", width: "150" },
        { label: "五月标准工作日", prop: "total_day5", width: "150" },
        { label: "六月标准工作日", prop: "total_day6", width: "150" },
        { label: "七月标准工作日", prop: "total_day7", width: "150" },
        { label: "八月标准工作日", prop: "total_day8", width: "150" },
        { label: "九月标准工作日", prop: "total_day9", width: "150" },
        { label: "十月标准工作日", prop: "total_day10", width: "150" },
        { label: "十一月标准工作日", prop: "total_day11", width: "150" },
        { label: "十二月标准工作日", prop: "total_day12", width: "150" },
      ],
      tableConfig10: [
        { label: "序号", type: "index", width: "60" },
        { label: "需求编号", prop: "req_id", width: "150" },
        { label: "服务单名称", prop: "req_name", width: "150" },
        { label: "当前节点", prop: "current_node", width: "200" },
        { label: "OA状态", prop: "oa_status", width: "200" },
        { label: "申请时间", prop: "applytime", width: "180" },
        { label: "开发负责人", prop: "dev_mgr", width: "180" },
        { label: "需求负责人", prop: "req_mgr", width: "180" },
        { label: "硬件金额（万元）", prop: "hardware_money", width: "180" },
        { label: "系统编号", prop: "sysno", width: "180" },
        { label: "系统名称", prop: "sysname", width: "150" },
        { label: "需求人员", prop: "req_man", width: "150" },
        { label: "开发人员", prop: "dev_man", width: "150" },
        { label: "实施内容", prop: "implement_common", width: "150" },
        { label: "资源类型", prop: "source_type", width: "150" },
        { label: "合作商", prop: "manufacturer", width: "150" },
        { label: "单价（万元）", prop: "price", width: "150" },
        { label: "预计人月", prop: "plan_month", width: "150" },
        { label: "预计IT投入（万元）", prop: "it_money", width: "150" },
        { label: "项目编号", prop: "project_num", width: "150" },
        { label: "实施周期", prop: "cycle", width: "150" },
        { label: "预计提交用户验收时间", prop: "check_time", width: "150" },
      ],
      loading: false,
      finished: false,
      name: "",
      noDataText:'您无查看权限',
      showLoading:true,
      isNoData:false
    };
  },
  mounted() {
    this.getTableOptions();
    if (this.$route.query.name) {
      this.name = this.$route.query.name;
    }
  },
  methods: {
    setForm(form) {
      this.form = form;
      this.query.page = 1;
      this.dataList = [];
      this.showMenu = false;
      this.loading = true;
      this.finished = false;
      this.getTableInfo();
    },
    handleType() {
      this.showPop = true;
    },
    onConfirm(value) {
      console.log(value);
      const index = this.columns.indexOf(value);
      this.chooseText = value;
      this.menuType = this.columnsId[index];
      this.showPop = false;
      this.loading = true;
      this.finished = false;
      // 获取新列表的数据
      if (this.menuType == 1) {
        this.form = createForm1();
      } else if (this.menuType == 2) {
        this.form = createForm2();
      } else if (this.menuType == 8) {
        this.form = createForm8();
      } else if (this.menuType == 9) {
        this.form = createForm9();
      } else if (this.menuType == 10) {
        this.form = createForm10();
      }
      this.query.page = 1;
      this.dataList = [];
      this.getTableInfo();
    },
    // 获取列表参数
    getTableOptions() {
      getTableOptions({}).then((res) => {
        console.log(res);
        if (res.data.length > 0) {
          this.columnsId = res.data.map((item) => item.id);
          this.columns = res.data.map((item) => item.name);
          this.query.type = this.columnsId[0];
          this.chooseText = this.columns[0];
          this.menuType = 1;
          this.form = createForm1();
          this.isNoData = false
          if (this.name) {
            this.homeTable();
          } else {
            // 获取列表参数后再处理
            this.getTableInfo();
          }
        }else{
          this.isNoData = true
        }
      });
    },
    //从首页跳到报表
    homeTable() {
      const index = this.columns.indexOf(this.name);
      this.chooseText = this.name;
      this.menuType = this.columnsId[index];
      this.showPop = false;
      // 获取新列表的数据
      if (this.menuType == 1) {
        this.form = createForm1();
      } else if (this.menuType == 2) {
        this.form = createForm2();
      } else if (this.menuType == 8) {
        this.form = createForm8();
      } else if (this.menuType == 9) {
        this.form = createForm9();
      } else if (this.menuType == 10) {
        this.form = createForm10();
      }
      this.query.page = 1;
      this.dataList = [];
      // this.getTableInfo();
    },
    getTableInfo() {
      const form = {
        ...this.form,
        ...this.query,
        type: this.menuType,
      };
      console.log(form)
      if(this.dataList.length==0){
        this.showLoading = true;
      }
      getTableInfo(form).then((res) => {
        console.log(res);

        if (res.data.length === 0 || res.data.length < 10) {
          this.finished = true;
        }
        this.dataList = this.dataList.concat(res.data);
        // this.showLoading = false;
        this.loading = false;
      });
    },
    onLoad() {
      this.query.page += 1;
      this.getTableInfo();
      // if(this.query.page>1){
        
      // }
    },
    filterChooseText(val) {
      console.log(val);
      if (val.length > 10) {
        return val.substr(0, 10) + "...";
      }
      return val;
    },
  },
};
</script>
<style lang="less" scoped>
.Declaration {
  background: #f7f9f9;
  padding-top: 50px;
  min-height: calc(100vh - (60px + env(safe-area-inset-bottom)));
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  box-sizing: border-box;
  &.full {
    position: fixed;
    transform: rotate(90deg);
  }
  /deep/ .van-popup--bottom {
    bottom: calc(60px + env(safe-area-inset-bottom));
  }
  .loading{
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
  }
}
.Declaration-head {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  height: 50px;
  line-height: 50px;
  padding: 0 15px;
  background: #fff;
  justify-content: space-between;
  z-index: 10;
  .title {
    // flex: 1;
    font-size: 17px;
    font-weight: bold;
    color: #313541;
    span {
      display: inline-block;
      font-weight: normal;
      transform: rotate(90deg);
      margin-left: 10px;
    }
  }
  .opera {
    .icon-shaixuan {
      margin-right: 25px;
    }
  }
}
</style>